package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.*;
import com.g8.pethospitallearnbackend.interceptors.AuthRequird;
import com.g8.pethospitallearnbackend.service.FlowService;
import com.g8.pethospitallearnbackend.service.OperationService;
import com.g8.pethospitallearnbackend.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;
    @Autowired
    private FlowService flowService;
    @Autowired
    private OperationService operationService;

    @RequestMapping("/log")
    public String printLogTest(){
        log.info("打印日志get");
        return "使用slf4j打印日志";
    }

    @GetMapping("")
    public List<Role> getAllRoles() {
//        return roleService.getAllRoles(pageNow, pageSize);
        return roleService.getAllRoles();
    }

    @GetMapping("/{roleIdOrName}")
    public Role getARole(@PathVariable String roleIdOrName) {
        return roleService.getARole(roleIdOrName);
    }

    @GetMapping("/flow/{flowId}")
    public Flow getAFlowById(@PathVariable String flowId) {
        return flowService.getAFlowById(flowId);
    }

    @GetMapping("/operation/{opId}")
    public Operation getAOperationById(@PathVariable String opId) {
        return operationService.getAOperationById(opId);
    }

    @GetMapping("/flow/name/{flowName}")
    public List<Flow> getFlowsByName(@PathVariable String flowName) {
        return flowService.getFlowsByName(flowName);
    }

    @GetMapping("/operation/name/{opName}")
    public List<Operation> getOperationsByName(@PathVariable String opName) {
        return operationService.getOpsByName(opName);
    }

    @AuthRequird
    @PostMapping("/operation")
    public Operation addAOperation(@RequestBody Operation operation) {
        return operationService.addAOperation(operation);
    }

    @AuthRequird
    @PutMapping("/operation")
    public Operation modifyOperation(@RequestBody Operation operation) {
        return operationService.modifyOperation(operation);
    }

    @AuthRequird
    @DeleteMapping("/operation/{opId}")
    public String deleteOperation(@PathVariable String opId) {
        return operationService.deleteAOp(opId);
    }

    @AuthRequird
    @PostMapping("/flow")
    public Flow addAFlow(@RequestBody Flow flow) {
        return flowService.addAFlow(flow);
    }

    @AuthRequird
    @PutMapping("/flow")
    public Flow modifyAFlow(@RequestBody Flow flow) {
        return flowService.modifyAFlow(flow);
    }

    @AuthRequird
    @DeleteMapping("/flow/{flowId}")
    public String deleteAFlow(@PathVariable String flowId) {
        return flowService.deleteAFlow(flowId);
    }

    @AuthRequird
    @PostMapping("")
    public Role addARole(@RequestBody Role role) {
        return roleService.addARole(role);
    }

    @AuthRequird
    @PutMapping("")
    public Role modifyARole(@RequestBody Role role) {
        return roleService.modifyARole(role);
    }

    @AuthRequird
    @DeleteMapping("/{roleId}")
    public String deleteARole(@PathVariable String roleId) {
        return roleService.deleteARole(roleId);
    }

    @AuthRequird
    @PutMapping("/flow-order")
    public String modifyFLowOrderInBulk(@RequestBody FlowOrderChangeInBulk flowOrderChangeInBulk) {
        return flowService.modifyFLowOrderInBulk(flowOrderChangeInBulk);
    }

    @AuthRequird
    @PutMapping("/operation-order")
    public String modifyOperationOrderInBulk(@RequestBody OperaOrderChangeInBulk operaOrderChangeInBulk) {
        return operationService.modifyOpOrderInBulk(operaOrderChangeInBulk);
    }

}
